<template>
    <div class="order-main all-main record-all">
        <section class="order-main-header">
             <mt-header title="我的收益">
            <mt-button  icon="back" slot="left" @click="handleClose()"></mt-button>
            </mt-header>
        </section>
        <div class="load-content">
            <div class="load-main">
                <div class="container">
                     <div class=" nav">
                        <mt-button  v-bind:class="active=='tab-container1'?'active':''" size="small" @click="changeActive('tab-container1')">收益记录</mt-button>
                        <mt-button v-bind:class="active=='tab-container2'?'active':''" size="small" @click="changeActive('tab-container2')">邀请记录</mt-button>
                    </div>
                    <div class="page-tab-container" >
                        <mt-tab-container class="page-tabbar-tab-container content"  value="tab-container1" v-model="active">
                            <mt-tab-container-item id="tab-container1" v-if="active=='tab-container1'">
                                <div v-if="profitList.length>0">
                                    <div class="order-table" v-for="(orderData, i) in profitList" v-bind:key="i" >
                                        <div class="order-header">
                                            <div class="flex-between ">
                                                <span v-if="orderData.type==1">交易返佣</span>
                                                <span v-if="orderData.type==2">团队奖励</span>
                                                <span v-if="orderData.type==3">平级奖励</span>
                                                <span v-if="orderData.type==4">全球分红</span>
                                                <span v-if="orderData.type==5">分享奖励</span>
                                            </div>
                                        </div>
                                        <div class="order-content flex-between">
                                            <div class="flex-center">
                                            <div class="all-amount">
                                                <span>数量({{symbol.fShortName}})</span>
                                                <span>{{orderData.commission}}</span>
                                            </div>
                                            <div class="all-amount">
                                                <span>返佣ID</span>
                                                <span v-if="orderData.type!=1">{{'-'}}</span>
                                                    <span v-if="orderData.type==1">{{orderData.userId}}</span>
                                            </div>
                                            <div class="all-amount">
                                                <span>时间</span>
                                                <span>{{timestampToTime(orderData.createDate)}}</span>
                                            </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div v-if="profitList.length==0" class="data-img">
                                    <img src="../../assets/noData.png">
                                    <p>暂无数据</p>
                                </div>
                            </mt-tab-container-item>
                            <mt-tab-container-item id="tab-container2"  >
                                <div v-if="inviteRecondList.length>0">
                                    <div class="order-table invite-table" v-for="(orderData, i) in inviteRecondList" v-bind:key="i" >
                                        <div class="order-content flex-between">
                                            <div class="flex-center">
                                            <div class="all-amount">
                                                <span>邀请账号</span>
                                                <span class="invite">{{loginName(orderData.loginName)}}</span>
                                            </div>
                                            <div class="all-amount">
                                                <span>业绩</span>
                                                <span class="invite" >{{orderData.achievement}}</span>
                                            </div>
                                            <div class="all-amount">
                                                <span>邀请时间</span>
                                                <span class="invite">{{timestampToTime(orderData.fRegisterTime)}}</span>
                                            </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div v-if="inviteRecondList.length==0" class="data-img">
                                    <img src="../../assets/noData.png">
                                    <p>暂无数据</p>
                                </div>
                            </mt-tab-container-item>
                        
                        </mt-tab-container>
                    </div>
                </div>
            </div>
        </div>
        <mt-actionsheet
        :actions="actions"
       v-model="sheetVisible" >
        </mt-actionsheet>
    </div>
</template>
<script>
import { Toast } from 'mint-ui';
import { MessageBox } from 'mint-ui';
import { Actionsheet } from 'mint-ui';
export default {
    name:'myOrder',
    components: {},
    data(){
         return {
             symbol:'',
             orderTabs:1, active: "tab-container1",
             profitList:[],
             fid:'',
             rewards:'',
             inviteCoinName:'',
             inviteRecondList:[],
                 sheetVisible:false,
                 recondAction:1,
               actions: [{
        name: '一级邀请',
        method :this.oneRecond
      }, {
        name: '二级邀请', 
        method :this.twoRecond
        }],
         }
    },
   
    mounted() {
        
         this.$http.post('v1/session?'+ new Date().getTime(),).then((res)=>{
            this.sessionData=res.data.data;
              this.getOtcList();
        })
        if(localStorage.getItem("recond")==1){
            this.recondAction=1
        }else if(localStorage.getItem("recond")==2){
            this.recondAction=2
        }
    },
    methods: {   
        loginName(res){
            return res.substring(0,3)+'****'+res.substring(res.length-5,res.length);
        },
                handleSheet(){
            this.sheetVisible=true;
        },
        oneRecond(){
                localStorage.setItem("recond",1);
                 this.recondAction=1;
                 this.inviteRecond(this.symbol);
        },
         twoRecond(){
             localStorage.setItem("recond",2);
              this.recondAction=2;
               this.inviteRecond(this.symbol);
        },
          profit(current){
              let self=this;
                  this.$http.post('/v2/bankerWallet/profitList',{userId: this.sessionData.id,fViFId:current.coinId}).then((res)=>{
                if(res.data.code==0){
                    self.profitList=res.data.data;
                    console.log(self.profitList.length)
                }
             })
        },
       getOtcList(){this.$http.post('/v2/market/allcoins',).then((res)=>{
                let tickers = res.data;
                 let coinGroup = {}
                    let param = location.hash.match(new RegExp(".*" + 'symbol' + "=([^\&]*)(\&?)", "i"));
                    let symbol = param && !isNaN(param[1]) ? param[1] : 0;
                    let current = null;
                    for (let i = 0; i < tickers.length; i++) {
                        let ticker = tickers[i]
                        if(ticker.report){
                            current = ticker
                        }
                    }
                    this.symbol=current;
                     this.profit(current);
             })
       },
        inviteRecond(current){
              let self=this;
            this.$http.post('/v2/bankerWallet/inviteRecond',{userId: this.sessionData.id,fViFId:this.symbol.coinId,pageNum:20,pageindex:1}).then((res)=>{
                if(res.data.code==0){
                    if(res.data.data==null){
                            self.inviteRecondList=[]
                    }else{
             self.inviteRecondList=res.data.data;
                    }
                }
             })
        },
        tabOrder(data){
            this.orderTabs=data
        },
         changeActive(id){
                this.active = id
                if(this.active=="tab-container1"){
                    this.profit(this.symbol);
                }else  if(this.active=="tab-container2"){
                   this.inviteRecond(this.symbol);
                }
            },
            handleClose(){
                this.$router.go(-1);
            },
            
                  timestampToTime (cjsj) {
        var date = new Date(cjsj) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-'
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
        var D = date.getDate() + ' '
        var h = date.getHours() + ':'
        var m = date.getMinutes() + ':'
        var s = date.getSeconds()
        return Y+M+D+h+m+s
       
    },
    },
}
</script>
<style lang="less" scoped>

.order-main .sell{
width: 50%;
height: 100px;
line-height: 100px;
text-align: center;
}
.order-main-header{
    display: flex;
    flex-direction: row;
    height: 100px;
}
.all-main{
    margin-bottom: 120px;
}
.all-amount{
     display: flex;
    flex-direction: column;
    height: 80px;
    text-align: center;
}
.order-content .all-amount:nth-child(1){
    width: 30%;
    text-align: left
}
.order-content .all-amount:nth-child(2){
    width: 20%;
    text-align: center;
}
.order-content .all-amount:nth-child(3){
    width: 50%;
    text-align: right;
}
.all-amount span:nth-child(1){
    height: 60px;
    line-height: 60px;
}
.order-main-header header{
    width: 100%;
}
.page-tab-container{
    height: 100%;
}
.data-img{
        min-height: 850px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column
}
.data-img img{
     width: 120px;
    height: 120px;
}
.order-content .left{
    color: #E0E0F9
}
.order-header{
    height: 80px;
    line-height: 80px;
    border-bottom:1px solid #161736;
    color: #ADADD8
}
.rect{
    height:10px;
    background:rgba(244,244,244,1);
}
.order-content{
    padding-top: 20px;
    color: #ADADD8;
    font-size: 24px;
}
.order-main .left p{
    height: 40px;
    font-size: 24px;
}
.record-all .nav{
    display: flex;
    flex-direction: row;
    height: 100px;
    line-height: 100px;
    background: #161736;
}
.black{
    color: #E0E0F9;
    font-weight:600;
    font-size:32px;
}
.flex-center{
    display: flex;
   align-self: center;
}
.all-main .flex-center{
width: 100%;
}
.flex-between{
      display: flex;
        justify-content: space-between;
    }
    .end{
        background: #8c9fad
    }
    .start{
          background:#5298FE;
          border-radius:6px;
    }
    .submit {
    width: 120px;
    height: 48px;
    font-size: 28px;
    line-height: 48px;
    font-weight: 700;
    color: #fff;
    border-radius:5px;
}
.order-header>div{
    align-items: center;
}
.order-table{
    padding: 20px 30px 20px 30px;
    background: #222240;
    position: relative;
    margin: 20px;
}
.tabs .img{
    width: 40px;
    height: 40px;
    position: relative;
    right: 20px;
    top:30px;
}
.order-main .buy{
width: 50%;
height: 100px;
line-height: 100px;
text-align: center;
}
.order-main .buy span{
text-align: center;
width: 50%;
line-height: 100px;
height: 90%;
}
.flex-content{
      display: -ms-flexbox;
    display: flex;
    justify-content: center;
}
.order-main .sell span{
width: 50%;
height: 90%;
line-height: 100px;
}
.tab-content{
    width: 80%;
    margin: 0 auto;
    font-size: 32px;
    font-weight:500;
}
.order-main .tab{
display: flex;
background:rgba(255,255,255,1);
height: 100px;
border-bottom:1px solid #161736
}
.order-main .active{
color: #3381FF;
}
.mint-header{
    height: 100px;
    font-size: 32px;
    background-color: #161736;
    color: #E0E0F9
}
.data-img p{
color: #fff;
}
.invite{
    height: 60px;
    line-height: 60px;
}
.all-main .invite-table{
    height: 140px;
}
  .load-content{
           position: absolute;
           top:130px;
           bottom: 0px;
           width: 100%;
           overflow-y: scroll;
           -webkit-overflow-scrolling:touch
       }
       .load-main{
           height: 100%;
       }
</style>